package com.wwwarehouse.usercenter.fragment.business_relationship;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.eventbus_event.CardDeskEvent;
import com.wwwarehouse.usercenter.R;

import de.greenrobot.event.EventBus;

/**
 * Created by xiaoke.ni on 2017/10/23.
 */

public class BRInviteFriendsSuccessFragment extends BaseFragment implements View.OnClickListener {

    private View mView;

    private ImageView mSuccessIv;
    private TextView mSuccessTv;
    private TextView mLine1Tv;
    private TextView mLine2Tv;
    private Button mSureBtn;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = View.inflate(getActivity(), R.layout.fragment_br_invite_friends_success, null);
        return mView;
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initEvent();
    }

    private void initView() {
        mSuccessIv = (ImageView) mView.findViewById(R.id.success_iv);
        mSuccessTv = (TextView) mView.findViewById(R.id.success_tv);
        mLine1Tv = (TextView) mView.findViewById(R.id.line1_tv);
        mLine2Tv = (TextView) mView.findViewById(R.id.line2_tv);
        mSureBtn = (Button) mView.findViewById(R.id.sure_btn);
    }

    private void initEvent() {
        mSureBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.sure_btn) {
            EventBus.getDefault().post(new CardDeskEvent("clear_back_stack"));
        }
    }

    @Override
    public void setTitle() {

    }

    @Override
    public void requestDatas() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            String isAgree = bundle.getString("isAgree");
            String inviterBuName = bundle.getString("inviterBuName");
            String inviterUserName = bundle.getString("inviterUserName");
            String inviteType = bundle.getString("inviteType");
            if ("AGRESS".equals(isAgree)) {
                mSuccessTv.setText(getString(R.string.user_br_successful_partnership));
                if ("CUSTOMER".equals(inviteType)){
                    mLine1Tv.setText(getString(R.string.user_br_you_became) + inviterBuName + getString(R.string.user_br_the) + getResources().getString(R.string.br_customer));
                }else if ("SUPPLIER".equals(inviteType)){
                    mLine1Tv.setText(getString(R.string.user_br_you_became) + inviterBuName + getString(R.string.user_br_the) + getResources().getString(R.string.br_supplier));
                }
                mLine1Tv.setText(getString(R.string.user_br_you_became) + inviterBuName + getString(R.string.user_br_the_customer));
                mLine2Tv.setText(getString(R.string.user_br_salesman_colon) + inviterUserName);
            } else {
                mSuccessIv.setBackground(getResources().getDrawable(R.drawable.upshot_success_yellow));
                mSuccessTv.setText(getString(R.string.user_br_refused_success));
                mLine1Tv.setText(getString(R.string.user_br_you_rejected) + inviterBuName + getString(R.string.user_br_initiate_invitation));
                mLine2Tv.setText("");
            }
        }
    }
}
